﻿using SharpDX;
using SharpDX.Toolkit;
using SharpDX.Toolkit.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bikiball.Graphic
{
    public class DefaultGraphicProperty : GraphicProperty
    {
        public override void Draw(Matrix World, Matrix View, Matrix Proj, GameTime GameTime)
        {
            BasicEffect effect = (BasicEffect) this.Effect;
            //graphProp.Effect.Parameters["time"].SetValue(i++ / 50.0f);
            GraphicEngine.GraphicsDevice.SetVertexBuffer(0, this.VertexBuffer, this.VertexStride);
            GraphicEngine.GraphicsDevice.SetVertexInputLayout(this.InputLayout);
            effect.View = View;
            effect.World = World;
            effect.Projection = Proj;
            effect.Texture = (Texture2D) this.Texture;
            if (this.IndexBuffer != null)
            {
                GraphicEngine.GraphicsDevice.SetIndexBuffer(this.IndexBuffer, true);
                foreach (EffectPass pass in this.Effect.Techniques[0].Passes)
                {
                    pass.Apply();
                    GraphicEngine.GraphicsDevice.DrawIndexed(PrimitiveType.TriangleList, this.NumIndices);
                }
            }
            else
                foreach (EffectPass pass in this.Effect.Techniques[0].Passes)
                {
                    pass.Apply();
                    GraphicEngine.GraphicsDevice.Draw(PrimitiveType.TriangleList, this.NumVertices);
                }
        }
    }
}
